home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 9798 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.9 KB

  1. Path: newshost.lanl.gov!tanmoy
  2. From: tanmoy@qcd.lanl.gov (Tanmoy Bhattacharya)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Quotes in C comments
  5. Date: 13 Mar 1996 16:25:51 GMT
  6. Organization: Los Alamos National Laboratory
  7. Message-ID: <TANMOY.96Mar13092551@qcd.lanl.gov>
  8. References: <Do6nn5.5rE@oscar.prima.ruhr.de>
  9. NNTP-Posting-Host: qcd.lanl.gov
  10. Mime-Version: 1.0
  11. Content-Type: text
  12. In-reply-to: patrick@oscar.prima.ruhr.de's message of Wed, 13 Mar 1996 01:47:29 GMT
  13.  
  14. In article <Do6nn5.5rE@oscar.prima.ruhr.de>
  15. patrick@oscar.prima.ruhr.de (Patrick Mau) writes:
  16. <snip>
  17. PM: I had a really funny problem with quotes in C programs:
  18.  
  19. Let us first decide what we are talking about: the language C has a
  20. very standardized meaning today. In the past the same name had been
  21. used for many of its predecessors, which were specified only by what
  22. the compilers did. Since you said C, I shall assume you meant the
  23. language we call C today.
  24.  
  25. PM: 
  26. PM: The question is:
  27. PM:  How should a compiler handle the following comments
  28. PM: 
  29. PM: First Example:
  30. PM: 
  31. PM: /*
  32. PM:  *  printf( "/* funny printf */" );
  33. PM:  *                           ^^--- Point A
  34. PM:  */
  35. PM: 
  36. PM: Second Example:
  37. PM: 
  38. PM:  /*
  39. PM:   *  You can't do xyz here
  40. PM:   *         ^--- Point B
  41. PM:   */
  42. PM: 
  43. PM: In the first example the compiler could stop at point A thinking the
  44. PM: comment ends at that point. This would be the case if the compiler
  45. PM: doesn't check quotes within comments. ( they are usually ignored. )
  46.  
  47. Quotes in comments get no special treatment: the very first */ inside
  48. a comment ends the comment. (Note that /* has no special treatment
  49. either, so comments cannot nest.) So, your comment indeed ends at
  50. point A. 
  51.  
  52. PM: 
  53. PM: In the second example ( _that_ happened to me with gcc 2.7.2 )
  54. PM: the compiler complains about an unterminated character constant
  55. PM: at EOF and says it could be at point B.
  56.  
  57. If this is really true, throw away the compiler. The only character
  58. sequence of any significance within a comment is */, because that ends
  59. the comment.
  60.  
  61. Could you post a small example showing this (and the exact error
  62. message that gcc produces)? I am 99% sure that what you are saying is
  63. not correct.
  64.  
  65. Are you confusing #if 0 with a comment?
  66.  
  67. PM: 
  68. PM: How should a good compiler handle those kinds of comments.
  69. PM: Should it check for quotes within comments or not ?
  70.  
  71. Quotes within comments are just ordinary characters and need no
  72. special treatment. A /* inside a quote or a comment does not start a
  73. comment.
  74.  
  75. Cheers
  76. Tanmoy
  77. --
  78. tanmoy@qcd.lanl.gov(128.165.23.46) DECNET: BETA::"tanmoy@lanl.gov"(1.218=1242)
  79. Tanmoy Bhattacharya O:T-8(MS B285)LANL,NM87545 H:#9,3000,Trinity Drive,NM87544
  80. Others see <gopher://yaleinfo.yale.edu:7700/00/Internet-People/internet-mail>,
  81. <http://alpha.acast.nova.edu/cgi-bin/inmgq.pl>or<ftp://csd4.csd.uwm.edu/pub/
  82. internetwork-mail-guide>. -- <http://nqcd.lanl.gov/people/tanmoy/tanmoy.html>
  83. fax: 1 (505) 665 3003   voice: 1 (505) 665 4733    [ Home: 1 (505) 662 5596 ]
  84.